/*------------------------------------------------------------------------------

Publication: Schakel, W. (2020) Representing the Rich: Economic and Political
	Inequality in Established Democracies. University of Amsterdam: Doctoral
	Dissertation.

Chapter: 3

Description: This do-file contains the commands for the figures presented in
	chapter 3.

Sections:

	1. Figure 3.1 (low- and high-income preferences)
	2. Figure 3.2 (predicted probability of policy change by income)
	3. Figure 3.3 (predicted probability of policy change when preferences diverge)

Data: Schakel_2020_Chapter3_1_Data (see Schakel_2020_Chapter3_1_Preparation
	do-file for original sources)

------------------------------------------------------------------------------*/

global data "YOUR PATH HERE"

/*------------------------------------------------------------------------------
 1. Figure 3.1 (low- and high-income preferences)
------------------------------------------------------------------------------*/

use "$data\Schakel_2020_Chapter3_1_Data.dta", clear

twoway (scatter i10 i90 if pass==0, m(circle) mc(gs13) msiz(medsmall))		///
	(scatter i10 i90 if pass==1, m(circle) mc(gs8) msiz(medsmall)			///
	xlab(0(20)100) ylab(0(20)100, nogrid angle(hor)) 						///
	xtit(90th income percentile (percent in favor), m(0 0 1 1))				///
	ytit(10th income percentile (percent in favor), m(zero))				///
	graphr(m(1 4 0 2) c(white)) plotr(m(zero)) xsize(10) ysize(8)			///
	legend(order(2 "Passed" 1 "Not passed")) xli(50, lc(gs0)) yli(50, lc(gs0)))

/*------------------------------------------------------------------------------
 2. Figure 3.2 (predicted probability of policy change by income)
------------------------------------------------------------------------------*/

use "$data\Schakel_2020_Chapter3_1_Data.dta", clear

* With the following loop, I generate and save the predicted probabilities
quietly foreach var of varlist i10 i50 i90 {
	logit pass `var'
	margins, at(`var'=(10(1)90))
	matrix `var'_=r(table)'
	svmat `var'_
	}

range x 10 90 81

twoway (line i90_1 x, lc(gs0) lw(medthick))									///
	(line i10_1 x, lc(gs13) lw(medthick))									///
	(line i50_1 x, lc(gs9) lw(medthick)										///
	xt(Percent in favor, m(0 0 0 2))										///
	yt(Predicted probability of change, m(zero))							///
	xlab(0(20)100) ylab(0(.2)1, angle(hor) nogrid)							///
	legend(order(2 "10th percentile" 3 "50th percentile"					///
	1 "90th percentile") row(1) symx(8))									///
	plotr(m(zero) lc(white)) graphr(m(2 4 0 2) fc(white) lc(white)))

drop i10_1-x

/*------------------------------------------------------------------------------
 3. Figure 3.3 (predicted probability of policy change when preferences diverge)
------------------------------------------------------------------------------*/

use "$data\Schakel_2020_Chapter3_1_Data.dta", clear

gen diff5090=abs(i50-i90)
range x 10 90 81

* With the following loop, I generate and save the predicted probabilities
foreach var of varlist i50 i90 {
	qui logit pass `var' if diff5090>10, or
	qui margins, at(`var'=(10(1)90))
	matrix `var'_=r(table)'
	svmat `var'_
	}

twoway (line i50_1 x, lc(gs11) lw(medthick))								///
	(rline i50_5 i50_6 x, lc(gs11) lp(dash))								///
	(line i90_1 x, lc(gs0) lw(medthick))									///
	(rline i90_5 i90_6 x, lc(gs0) lp(dash)									///
	xt(Percent in favor, m(0 0 0 2))										///
	yt(Predicted probability of change, m(zero))							///
	xlab(0(20)100) ylab(0(.2)1, nogrid angle(hor))							///
	legend(order(1 "50th percentile" 3 "90th percentile") symx(8))			///
	plotr(m(zero) lc(white)) graphr(m(2 4 0 2) fc(white) lc(white)))

drop diff5090-i90_9
